package com.tcm.ucenter.service;

import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@DubboService(version = "0.0.1-alpha", delay = -1)
public class UserAccountChangeFactory implements UserAccountFactory {

    private final Logger log = LoggerFactory.getLogger(UserAccountChangeFactory.class);
    private static final Map<String, UserAccountChangeService> strategyMap = new HashMap<>();

    // 构造函数，如果是集合接口对象，那么会把spring容器中所有关于该接口的子类，全部抓出来放入到集合中
    public UserAccountChangeFactory(List<UserAccountChangeService> strategyList) {
        for (UserAccountChangeService strategy : strategyList) {
            strategyMap.put(strategy.supports(), strategy);
        }
    }

    public UserAccountChangeService account(String type) {
        UserAccountChangeService strategy = strategyMap.get(type);
        return strategy;
    }
}
